package written.test;

import java.util.*;

/**
 * @Author: Dang Qi
 * @Date: 2021/4/7  19:00
 * @Description:
 */
public class Huawei1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        set = new HashSet<>();
        parent = new HashMap<>();
        for(int i = 0; i < N; i++){
            union(sc.next(), sc.next());
        }
        System.out.println(set.size()-count);
    }
    static int count=0;
    static Set<String> set = null;
    static Map<String, String> parent ;
    public static void union(String x, String y){
        set.add(x);set.add(y);
        String x_root = findRoot(x);
        String y_root = findRoot(y);
        if(x_root.equals(y_root)) return;
        parent.put(x_root, y_root);
        count++;
    }
    public static String findRoot(String x){
        while (parent.get(x)!=null){
            String grandp = parent.get(parent.get(x));
            if(grandp!=null) parent.put(x, grandp);
            x = parent.get(x);
        }
        return x;
    }
}
